<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>五角星评分案例</title>
    <style>
        body {
            font-family: "simsun";
        }

        .comment {
            font-size: 40px;
            color: #ff1100;
        }

        .comment li {
            float: left;
            cursor: pointer;
        }

        ul {
            list-style: none;
        }
    </style>
    <script src="../jquery-1.11.1.js"></script>
    <script>
        jQuery(document).ready(function ($) {
            let index = -1;
            $('.comment').on('mouseenter', 'li', function (e) {
                star($(this).index());
            });
            $('.comment').on('click', 'li', function (e) {
                // 点击时索引
                index = $(this).index();
            });
            $('.comment').on('mouseleave', 'li', function (e) {
                star(index);
            })
        });

        // 标记星级
        function star(index) {
            $('.comment li').each(function (i, el) {
                if (i <= index) {
                    $(el).text('★');
                } else {
                    $(el).text('☆');
                }
            });
        }
    </script>
</head>

<body>


    <ul class="comment">
        <li>☆</li>
        <li>☆</li>
        <li>☆</li>
        <li>☆</li>
        <li>☆</li>
    </ul>


</body>

</html>